package de.gameduell.framework.gui.animation {
	import Singularity.Geom.Composite;
	
	import fl.transitions.TweenEvent;
	
	import flash.events.EventDispatcher;		

	/**
	 * @author cbra
	 */
	public class PathTween extends EventDispatcher implements Tweenable {

		private var timeTween:GDTween;
		private var _tweenedObject:Object;
		private var _composite:Composite;

		public function PathTween(tweenedObject:Object,aComposite:Composite,EaseType:Function,startValue:Number,endValue:Number, duration:Number, useSeconds:Boolean) {
			_tweenedObject = tweenedObject;
			timeTween = new GDTween(this,"t",EaseType,startValue,endValue,duration,useSeconds);	
			timeTween.addEventListener(TweenEvent.MOTION_FINISH, onMotionEvent);
			timeTween.addEventListener(TweenEvent.MOTION_CHANGE, onMotionEvent);
			_composite = aComposite;
		}

		public function set t(time:Number):void{
			_tweenedObject["x"] = _composite.getX(time);
			_tweenedObject["y"] = _composite.getY(time);
		}
		
		public function start():void {
			timeTween.start();
		}
		
		public function stop():void {
			timeTween.start();
		}
		
		public function get isPlaying():Boolean {
			return timeTween.isPlaying;
		}
		
		private function onMotionEvent(event:TweenEvent):void {
			dispatchEvent(event.clone());
		}
	}
}
